package com.daatak.mvc.common;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.daatak.mvc.domain.LovObject;
import com.daatak.mvc.domain.MenuObject;

@Repository
@Transactional
public class UtilityDao {
	
	 @Autowired
	 private SessionFactory sessionFactory;
	
	 public void setSessionFactory(SessionFactory sessionFactory) {
		 this.sessionFactory = sessionFactory;
	       // hibernateTemplate = new HibernateTemplate(sessionFactory);
	    }

	   public Session getCurrentSession()
	   {
		   return sessionFactory.getCurrentSession();
	   }
	    public void createMenu(MenuObject menuObject) {
	    	
	    	getCurrentSession().save(menuObject);

	    }
	    
	    
	    
	    public List<MenuObject> getMenuList() {
	    	
	    	return   getCurrentSession().createCriteria(MenuObject.class).list();

	    }
	    
	  
	    public List<LovObject> getLovList(String lovCode) {
	    	
	    	Session session = sessionFactory.getCurrentSession();
	    	return   session.createCriteria(LovObject.class)
	    		    .add( Restrictions.eq("code", lovCode) )
	    		    .list();

	    }
	    @Transactional(readOnly = true)
	    public List<LovObject> getLovList(String lovCode,String view) {
	    	/*System.out.println("lov code---"+lovCode+"------view-----"+view);
	    	SQLQuery query = hibernateTemplate.getSessionFactory().openSession().createSQLQuery("select id, value, label, null as code,null as LOV_TYPE, null as description,null as img_src, null as parent_code, null as vendor_id from "+view).addEntity(LovObject.class);
	    	return query.list();*/
	    	return null;

	    }
	    
	  	    
}
